package cc.jorange.common;

import cc.jorange.bean.User;
import cc.jorange.common.security.Digests;


/**
 * 密码工具类
 * 
 * @author Aaron
 *
 */
public class PasswordHelper {

	private static final int SALT_SIZE = 8;
	private static final int HASH_INTERATIONS = 1024;

	/**
	 * 设定安全的密码，生成随机的salt并经过1024次 sha-1 hash
	 */
	public static void entryptPassword(User user) {
		byte[] salt = Digests.generateSalt(SALT_SIZE);
		user.setSalt(Encodes.encodeHex(salt));

		byte[] hashPassword = Digests.sha1(user.getPlainPassword().getBytes(), salt, HASH_INTERATIONS);
		user.setPassword(Encodes.encodeHex(hashPassword));
	}

}